<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>电话卡详情</title>
    <!-- 引入样式 -->
    <link rel="stylesheet" type="text/css" href="/assets/element-plus/index.css">
    <!-- 引入 Vue.js -->
    <script src="/assets/vue/vue.global.js"></script>
    <!-- 引入 Element Plus -->
    <script src="/assets/element-plus/index.full.js"></script>
    <!-- 引入 Axios -->
    <script src="/assets/axios/axios.js"></script>
    <!-- 引入自定义安全模块 -->
    <script src="/assets/oa/security.js"></script>
    <style>
        body {
            margin: 0;
            padding: 0;
            display: flex;
            justify-content: center;
            align-items: center;
            background-color: #f0f2f5;
        }
        /* 自定义样式 */
        .info-container {
            width: 900px;
            padding: 20px;
            background-color: #fff;
            border-radius: 8px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
            margin-top: 10px;
        }
        .info-item {
            margin-bottom: 15px;
        }
        .info-label {
            font-weight: bold;
            margin-right: 10px;
            width: 120px;
            display: inline-block;
        }
        .info-value {
            margin-left: 10px;
            color: #333;
        }
        h2 {
            margin-bottom: 10px;
            color: #333;
        }
        h3 {
            margin-top: 20px;
            margin-bottom: 10px;
            color: #333;
        }
        .billing-table {
            width: 100%;
            border-collapse: collapse;
            margin-top: 10px;
        }
        .billing-table th, .billing-table td {
            border: 1px solid #ddd;
            padding: 8px;
            text-align: left;
        }
        .billing-table th {
            background-color: #f2f2f2;
        }
        .no-info {
            color: #777;
            margin-top: 10px;
        }
    </style>
</head>
<body>
<div id="app">
    <!-- 页面标题 -->
    <h2>电话卡详情</h2>
    <!-- 电话卡信息展示区域 -->
    <div class="info-container">
        <!-- 订单基本信息 -->
        <div class="info-item">
            <span class="info-label">订单ID:</span>
            <span class="info-value">{{ order.orderid }}</span>
        </div>
        <div class="info-item">
            <span class="info-label">客户ID:</span>
            <span class="info-value">{{ order.customerid }}</span>
        </div>
        <div class="info-item">
            <span class="info-label">管理员ID:</span>
            <span class="info-value">{{ order.managerid }}</span>
        </div>
        <div class="info-item">
            <span class="info-label">订单状态:</span>
            <span class="info-value">{{ order.orderstatus }}</span>
        </div>
        <div class="info-item">
            <span class="info-label">订单价格:</span>
            <span class="info-value">{{ order.packagecost }}元</span>
        </div>
        <!-- 电话卡详情 -->
        <div class="info-item">
            <span class="info-label">电话卡号码:</span>
            <span class="info-value">{{ phoneCard.userPhone }}</span>
        </div>
        <div class="info-item">
            <span class="info-label">电话卡密码:</span>
            <span class="info-value">{{ phoneCard.userPassword }}</span>
        </div>
        <div class="info-item">
            <span class="info-label">电话状态:</span>
            <span class="info-value">{{ phoneCard.userStatus }}</span>
        </div>
        <!-- Billing Information -->
        <h3>账单信息</h3>
        <table class="billing-table" v-if="billingInfo.length">
            <thead>
            <tr>
                <th>账单ID</th>
                <th>主叫号码</th>
                <th>被叫号码</th>
                <th>被呼运营商</th>
                <th>被呼费用</th>
                <th>通话时长</th>
                <th>话费</th>
                <th>账单创建时间</th>
            </tr>
            </thead>
            <tbody>
            <tr v-for="bill in billingInfo" :key="bill.billID">
                <td>{{ bill.billID }}</td>
                <td>{{ bill.callingPhone }}</td>
                <td>{{ bill.calledPhone }}</td>
                <td>{{ bill.calledOperatorName }}</td>
                <td>{{ bill.calledPrice }}元/分钟</td>
                <td>{{ bill.callDuration }}分钟</td>
                <td>{{ bill.phoneCharge }}元</td>
                <td>{{ formatTimestamp(bill.createTime) }}</td>
            </tr>
            </tbody>
        </table>
        <div v-else class="no-info">No billing information available.</div>
    </div>
</div>

<script>
    // 获取 URL 参数
    const urlParams = new URLSearchParams(window.location.search);
    // 解析订单详情数据和电话卡详情数据
    const orderData = JSON.parse(decodeURIComponent(urlParams.get('orderData')));
    const phoneCardData = JSON.parse(decodeURIComponent(urlParams.get('phoneCardData')));

    // 创建 Vue 应用
    const app = Vue.createApp({
        data() {
            return {
                order: orderData,
                phoneCard: phoneCardData,
                billingInfo: []
            };
        },
        mounted() {
            this.fetchBillingInfo();
        },
        methods: {
            fetchBillingInfo() {
                // Make an Axios request to fetch billing information
                const userPhone = this.phoneCard.userPhone;
                axios.post("/phonebill/selectByUserPhone", { userPhone })
                    .then(response => {
                        this.billingInfo = response.data.data;
                    })
                    .catch(error => {
                        console.error("Error fetching billing information:", error);
                    });
            },
            formatTimestamp(timestamp) {
                if (!timestamp) return ''; // 如果时间戳不存在，则返回空字符串
                const date = new Date(timestamp);
                const year = date.getFullYear();
                const month = (date.getMonth() + 1).toString().padStart(2, '0');
                const day = date.getDate().toString().padStart(2, '0');
                const hours = date.getHours().toString().padStart(2, '0');
                const minutes = date.getMinutes().toString().padStart(2, '0');
                const seconds = date.getSeconds().toString().padStart(2, '0');
                return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
            }
        }
    });

    // 挂载至 #app
    app.mount("#app");
</script>

</body>
</html>
